package com.ymatou.operate.trading.api.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.OrderGroupVo;
import com.ymatou.iapi.trading.operate.parameter.OrderItemVo;
import com.ymatou.iapi.trading.operate.parameter.OrderVo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.SellerCouponVo;
import com.ymatou.iapi.trading.operate.parameter.YmatouCouponVo;
import com.ymatou.iapi.trading.operate.parameter.enums.AppTerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.OrderTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.PriceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.ProductRefundChannelEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SalesTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.SellerCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.TerminalSourceEnum;
import com.ymatou.iapi.trading.operate.parameter.enums.YmatouCouponApplianceTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.PlaceOrderCall;
import com.ymatou.operate.trading.api.parameter.BatchCancelOrderBean;
import com.ymatou.operate.trading.api.service.BatchCancelOrderCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.ProductCallService;
import com.ymttest.common.enums.CancelOrderTypeEnum;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 批量取消订单 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_BatchCancelOrder {

    private static BatchCancelOrderBean batchcancelorderbean;
    private static BatchCancelOrderCall batchcancelordercall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("批量取消订单");
    }

    @Before
    public void caseUp() {

        batchcancelorderbean = new BatchCancelOrderBean();
        batchcancelordercall = new BatchCancelOrderCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(batchcancelordercall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    // 创建一个订单，使用平台优惠券,商家优惠券
    private Map placeOrder() {
        Map map = new HashMap();
        try {
            PlaceOrderReq placeorderBean = new PlaceOrderReq();
            PlaceOrderCall placeorderCall = new PlaceOrderCall();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            // 创建产品
            Logger.comment("前置数据准备");
            HashMap<String, Object> productInfo = ProductCallService
                    .createProduct(sellerId, 3);
            Logger.comment("前置数据准备结束");
            String productId = (String) productInfo.get("productId");
            Logger.debug("productId:" + productId);
            String productName = (String) productInfo.get("productName");
            String pic = (String) productInfo.get("pic");
            BigDecimal price = (BigDecimal) (productInfo.get("price"));
            String catalogId = (String) productInfo.get("catalogId");
            YmatouCouponVo ymtCoupon = new YmatouCouponVo();
            // 平台优惠券
            BigDecimal couponValue = new BigDecimal(13);
            String couponCode = new OrderCallService().receivePlatformCoupon(userId, couponValue);
            ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
            ymtCoupon.setCouponCode(couponCode);
            ymtCoupon.setCouponValue(couponValue);
            placeorderBean.setAppId("AutoTest");
            placeorderBean.setYmatouCoupon(ymtCoupon);
            placeorderBean.setUserId(userId);
            placeorderBean.setRequestId(TestDataManager.getRandomUUID()
                    .toString());
            placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
            placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
            OrderGroupVo groupVo1 = new OrderGroupVo();
            // 商家优惠券
            BigDecimal sellerCouponValue = new BigDecimal(15);
            String sellerCouponCode = new CouponCallService().receiveCouponInfo(sellerId, userId,
                    couponValue);
            SellerCouponVo sellerCoupon = new SellerCouponVo();
            sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
            sellerCoupon.setCouponCode(sellerCouponCode);
            sellerCoupon.setCouponValue(sellerCouponValue);
            groupVo1.setSellerCoupon(sellerCoupon);
            groupVo1.setSellerId(sellerId);

            List<OrderVo> orders = new ArrayList<OrderVo>();
            OrderVo ordervo1 = new OrderVo();
            ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
            ordervo1.setOrderType(OrderTypeEnum.Spot);
            ordervo1.setPaidFull(true);

            List<OrderItemVo> items = new ArrayList<OrderItemVo>();
            OrderItemVo orderitem1 = new OrderItemVo();
            orderitem1.setProductNum(1);
            orderitem1.setProductName(productName);
            orderitem1.setPriceType(PriceTypeEnum.VipPrice);
            orderitem1.setProductId(productId);
            price = new BigDecimal(210);
            orderitem1.setEarnestPrice(price);
            orderitem1.setProductPrice(price);
            orderitem1.setOriginalPrice(price);
            orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem1.setProductRefundChannel(ProductRefundChannelEnum.Official);
            items.add(orderitem1);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("21"));

            orders.add(ordervo1);
            groupVo1.setOrders(orders);
            placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
            placeorderCall.setData(false, placeorderBean);
            placeorderCall.callService();

            YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
            List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
                    .selectBysCouponCode(couponCode);
            int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
            List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
                    .selectBysCouponCode(sellerCouponCode);
            int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

            map.put("orderId", placeorderCall.getOrderIds().get(0));
            map.put("tradingId", placeorderCall.getTradingId());
            map.put("sellerId", sellerId);
            map.put("userId", userId);
            map.put("ymtCouponCode", couponCode);
            map.put("sellerCouponCode", sellerCouponCode);
            map.put("ymtBeforeCount", ymtBeforeCount);
            map.put("sellerBeforeCount", sellerBeforeCount);
        } catch (Exception e) {
            Logger.fail(e);
        }
        return map;
    }

    // 创建一个买手2个订单，使用平台优惠券
    private Map placeOrder2() {
        Map map = new HashMap();
        try {
            PlaceOrderReq placeorderBean = new PlaceOrderReq();
            PlaceOrderCall placeorderCall = new PlaceOrderCall();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));

            String productName = "auto自动化测试";
            String pic = "http://p243.img.ymatou.com:10243/upload/productdes/3afa103d4ec4466f824b9f0458d6f4e2.jpg";
            BigDecimal price = new BigDecimal(130);
            String productId = "auto123456";
            YmatouCouponVo ymtCoupon = new YmatouCouponVo();
            // 平台优惠券
            BigDecimal couponValue = new BigDecimal(13);
            String couponCode = new OrderCallService().receivePlatformCoupon(userId, couponValue);
            ymtCoupon.setApplianceType(YmatouCouponApplianceTypeEnum.ALL);
            ymtCoupon.setCouponCode(couponCode);
            ymtCoupon.setCouponValue(couponValue);
            placeorderBean.setAppId("AutoTest");
            placeorderBean.setYmatouCoupon(ymtCoupon);
            placeorderBean.setUserId(userId);
            placeorderBean.setRequestId(TestDataManager.getRandomUUID()
                    .toString());
            placeorderBean.setTerminalSource(TerminalSourceEnum.IOS);
            placeorderBean.setAppTerminalSource(AppTerminalSourceEnum.Phone);
            OrderGroupVo groupVo1 = new OrderGroupVo();
            // 商家优惠券
            BigDecimal sellerCouponValue = new BigDecimal(15);
            String sellerCouponCode = new CouponCallService().receiveCouponInfo(sellerId, userId,
                    couponValue);

            SellerCouponVo sellerCoupon = new SellerCouponVo();
            sellerCoupon.setApplianceType(SellerCouponApplianceTypeEnum.ALL);
            sellerCoupon.setCouponCode(sellerCouponCode);
            sellerCoupon.setCouponValue(sellerCouponValue);
            groupVo1.setSellerCoupon(sellerCoupon);
            groupVo1.setSellerId(sellerId);
            List<OrderVo> orders = new ArrayList<OrderVo>();
            OrderVo ordervo1 = new OrderVo();
            ordervo1.setAutoCancelOrderHours(new BigDecimal(1));
            ordervo1.setOrderType(OrderTypeEnum.Spot);
            ordervo1.setPaidFull(true);

            List<OrderItemVo> items = new ArrayList<OrderItemVo>();
            OrderItemVo orderitem1 = new OrderItemVo();
            orderitem1.setProductNum(1);
            orderitem1.setProductName(productName);
            orderitem1.setPriceType(PriceTypeEnum.VipPrice);
            orderitem1.setProductId(productId);
            orderitem1.setCatalogId(TestDataManager.getRandomUUID().toString());
            price = new BigDecimal(210);
            orderitem1.setEarnestPrice(price);
            orderitem1.setProductPrice(price);
            orderitem1.setOriginalPrice(price);
            orderitem1.setSalesType(SalesTypeEnum.AlreadyInStock);
            orderitem1.setLogisticsType(LogisticsTypeEnum.SailProtect);
            orderitem1.setProductRefundChannel(ProductRefundChannelEnum.Official);
            items.add(orderitem1);
            ordervo1.setOrderItems(items);
            ordervo1.setFreight(new BigDecimal("21"));

            // 第三个订单
            orders.add(ordervo1);
            orders.add(ordervo1);
            orders.add(ordervo1);

            groupVo1.setOrders(orders);

            placeorderBean.setOrderGroups(Arrays.asList(groupVo1));
            placeorderCall.setData(placeorderBean);
            placeorderCall.callService();

            YmtCouponPrivateUserBoundWapper ymtCouponPrivate = new YmtCouponPrivateUserBoundWapper();
            List<YmtCouponPrivateUserBound> listCoupon = ymtCouponPrivate
                    .selectBysCouponCode(couponCode);
            int ymtBeforeCount = listCoupon.get(0).getiCouponUsedCount();
            List<YmtCouponPrivateUserBound> listCoupon2 = ymtCouponPrivate
                    .selectBysCouponCode(sellerCouponCode);
            int sellerBeforeCount = listCoupon2.get(0).getiCouponUsedCount();

            map.put("orderId", placeorderCall.getOrderIds());
            map.put("tradingId", placeorderCall.getTradingId());
            map.put("ymtCouponCode", couponCode);
            map.put("sellerCouponCode", sellerCouponCode);
            map.put("ymtBeforeCount", ymtBeforeCount);
            map.put("sellerBeforeCount", sellerBeforeCount);
        } catch (Exception e) {
            Logger.fail(e);
        }
        return map;
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_001() {
        Logger.start(true, "订单支付前,卖家批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int UserId = 0, SellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map<?, ?> map = placeOrder();
                SellerId = (Integer) map.get("sellerId");
                UserId = (Integer) map.get("userId");
                int OrderId = (Integer) map.get("orderId");
                OrderIdList.add(OrderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.SellerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(SellerId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            Logger.verifyEquals(ECode.SUCCESS, batchcancelordercall.getCode(), "验证Code");
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                int sellerId = batchcancelorderbean.getUserId();
                Logger.verifyEquals(13, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 13)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId, sellerId).size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_002() {
        Logger.start(true, "订单支付前,买家批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int UserId = 0, SellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map<?, ?> map = placeOrder();
                SellerId = (Integer) map.get("sellerId");
                UserId = (Integer) map.get("userId");
                int OrderId = (Integer) map.get("orderId");
                OrderIdList.add(OrderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(UserId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            Logger.verifyEquals(ECode.SUCCESS, batchcancelordercall.getCode(), "验证Code");
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                int sellerId = batchcancelorderbean.getUserId();
                Logger.verifyEquals(12, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId, sellerId).size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_003() {
        Logger.start(true, "订单支付前,系统批量取消订单成功");
        try {
            DefaultWapper database = new DefaultWapper();
            // 参数
            Logger.comment("前置数据准备");
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int UserId = 0, SellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map<?, ?> map = placeOrder();
                SellerId = (Integer) map.get("sellerId");
                UserId = (Integer) map.get("userId");
                int OrderId = (Integer) map.get("orderId");
                // 修改订单自动取消时间为0
                database.updateOrderAutoCancelOrderHoursByOrderId(0.00, OrderId);
                OrderIdList.add(OrderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.SystemCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(UserId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                int sellerId = batchcancelorderbean.getUserId();
                Logger.verifyEquals(18, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 18)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId, sellerId).size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_004() {
        Logger.start(true, "订单支付前,客服批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int UserId = 0, SellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map<?, ?> map = placeOrder();
                SellerId = (Integer) map.get("sellerId");
                UserId = (Integer) map.get("userId");
                int OrderId = (Integer) map.get("orderId");
                OrderIdList.add(OrderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(UserId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                int sellerId = batchcancelorderbean.getUserId();
                Logger.verifyEquals(13, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 13)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId, sellerId).size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_005() {
        Logger.start(true, "订单卖家已接单,,客服批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
            	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                // 接单
                orderService.acceptOrder(orderId, sellerId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                Logger.verifyEquals(13, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 13)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId,
                        userId).size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_006() {
        Logger.start(true, "订单已支付商家未接单,风控批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                // 风控取消
                YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("", "POST", "JSON");
                String RiskControlNotifyString = "{OrderId:" + orderId + ",ParamExt:{\"Status\":\"Rejected\"}}";
                RiskControlNotifyCall.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");
                RiskControlNotifyCall.setData(RiskControlNotifyString);
                Logger.comment("风控检测");
                RiskControlNotifyCall.callService();
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            /*
             * batchcancelorderbean.setOrderIdList(OrderIdList);
             * batchcancelorderbean.setCancelReason("自动化测试取消订单");
             * batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder); // 卖家ID
             * batchcancelorderbean.setUserId(userId); // 发送请求
             * batchcancelordercall.setData(batchcancelorderbean);
             * batchcancelordercall.callService();
             */
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = OrderIdList.get(i);
                Logger.verifyEquals(18, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 18)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId,
                        -1).size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_007() {
        Logger.start(true, "订单已支付商家未接单,买家批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                Logger.verifyEquals(12, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId,
                        userId).size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_008() {
        Logger.start(true, "订单已支付商家未接单,卖家批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.SellerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                Logger.verifyEquals(13, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 13)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId,
                        userId).size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_009() {
        Logger.start(true, "订单已支付商家未接单,客服批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();
            for (int i = 0; i < size; i++) {
                int orderId = batchcancelorderbean.getOrderIdList().get(i);
                Logger.verifyEquals(13, database.getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1, database.selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 13)
                        .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, database.selectOrderReasonByOrderIdAndUserId(orderId,
                        userId).size(), "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(orderId, batchcancelordercall.getCancelOrderResultList().get(i).getOrderId(),
                        "验证订单OrderId");
                Logger.verifyEquals(true, batchcancelordercall.getCancelOrderResultList().get(i).getIsSuccess(),
                        "验证订单取消状态");
                Logger.verifyEquals("", batchcancelordercall.getCancelOrderResultList().get(i).getResultInfo(),
                        "验证ResultInfo");
                Logger.verifyEquals(null, batchcancelordercall.getCancelOrderResultList().get(i)
                        .getThirdPartyRefundMessage(),
                        "验证ThirdPartyRefundMessage");
            }
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_010() {
        Logger.start(true, "订单在退货退款中,批量取消订单失败");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                // 退货退款同步
                orderService.applySalesRefundRequestInJava(orderId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            Logger.verifyEquals(ECode.FAILED201, batchcancelordercall.getString("Code"), "验证Code");
            Logger.verifyEquals("哈尼，" + batchcancelorderbean.getOrderIdList().get(0) + "此单有退货/退款，请先去处理~",
                    batchcancelordercall.getMsg(), "验证Msg");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_011() {
        Logger.start(true, "订单支付前,重复批量取消订单成功");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            Logger.comment("重复批量取消");
            batchcancelordercall.callService();
            // 验证数据库
            Logger.verifyEquals(ECode.FAILED201, batchcancelordercall.getString("Code"), "验证Code");
            Logger.verifyEquals(batchcancelorderbean.getOrderIdList().get(0) + "此订单已取消~",
                    batchcancelordercall.getMsg(), "验证Msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_012() {
        Logger.start(true, "订单号不存在,批量取消订单失败");
        try {
            // 参数
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 1113, sellerId = 3383;
            OrderIdList.add(111);
            OrderIdList.add(222);
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.CustomerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            Logger.comment("重复批量取消");
            batchcancelordercall.callService();
            // 验证数据库
            Logger.verifyEquals(ECode.FAILED201, batchcancelordercall.getString("Code"), "验证Code");
            Logger.verifyEquals("订单号不存在:" + batchcancelorderbean.getOrderIdList().get(0),
                    batchcancelordercall.getMsg(), "验证Msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_013() {
        Logger.start(true, "商家已接单,买家批量取消订单失败");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                // 接单
                orderService.acceptOrder(orderId, sellerId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(userId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            Logger.verifyEquals(ECode.FAILED201, batchcancelordercall.getString("Code"), "验证Code");
            Logger.verifyEquals("哈尼，你的订单" + batchcancelorderbean.getOrderIdList().get(0) + "，买手刚刚接单了，只能走退货退款流程了哦~"
                    ,
                    batchcancelordercall.getMsg(), "验证Msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_014() {
        Logger.start(true, "用户不是订单所有者,买家批量取消订单失败");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = 0, sellerId = 0;
            // 创建订单
            for (int i = 0; i < 2; i++) {
               	PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

            	int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
            	 sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
            	 userId =placeOrderResp.getUserId();         
            	int tradingId = placeOrderResp.getTradingId();

            	BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(1234);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            int size = OrderIdList.size();

            Logger.verifyEquals(ECode.FAILED201, batchcancelordercall.getString("Code"), "验证Code");
            Logger.verifyEquals("用户" + batchcancelorderbean.getUserId() + "不是订单" + OrderIdList.get(0) + "的所有者",
                    batchcancelordercall.getMsg(), "验证Msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }



    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_015() {
        Logger.start(true, "同时使用平台,商家优惠券，支付前接单前,批量取消订单,退回优惠券");
        try {
            // 参数
            Logger.comment("前置数据准备");
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map map = placeOrder();
                int orderId = (Integer) map.get("orderId");
                int tradingId = (Integer) map.get("tradingId");
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 买家付款
                // orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(sellerId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            // 数据库验证
            YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
            int size = OrderIdList.size();
            for (int orderId : OrderIdList) {
                // 订单主表
                List<Map> ymtOrders = database.selectOrderByOderId(orderId);
                // 订单结算
                List<Map> settlementList = database.selectYmtSettlementInvoice(orderId);
                // 付款金额
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 平台券
                String ymtCouponCode = (String) ymtOrders.get(0).get("sYmtCouponCode");
                // 商家券
                String sellerCouponCode = (String) ymtOrders.get(0).get("sSellerCouponCode");

                List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
                        .selectBysCouponCode(ymtCouponCode);
                List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
                        .selectBysCouponCode(sellerCouponCode);

                Logger.verifyEquals(12, new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1,
                        new DefaultWapper().selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                                .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, new DefaultWapper().selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
                        .size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(1, listCoupon1.get(0).getiCouponUsedCount(), "验证ymt平台优惠券退回");
                Logger.verifyEquals(1, listCoupon2.get(0).getiCouponUsedCount(), "验证商家优惠券退回");
            }


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_016() {
        Logger.start(true, "同时使用平台,商家优惠券，支付后接单前,批量取消订单,退回优惠券");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            // 创建订单
            for (int i = 0; i < 2; i++) {
                Map map = placeOrder();
                int orderId = (Integer) map.get("orderId");
                int tradingId = (Integer) map.get("tradingId");
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 买家付款
                orderService.orderPayRequest(userId, totalPrice, tradingId);
                OrderIdList.add(orderId);
            }
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(sellerId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            // 数据库验证
            YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
            int size = OrderIdList.size();
            for (int orderId : OrderIdList) {
                // 订单主表
                List<Map> ymtOrders = database.selectOrderByOderId(orderId);
                // 订单结算
                List<Map> settlementList = database.selectYmtSettlementInvoice(orderId);
                // 付款金额
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 平台券
                String ymtCouponCode = (String) ymtOrders.get(0).get("sYmtCouponCode");
                // 商家券
                String sellerCouponCode = (String) ymtOrders.get(0).get("sSellerCouponCode");

                List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
                        .selectBysCouponCode(ymtCouponCode);
                List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
                        .selectBysCouponCode(sellerCouponCode);

                Logger.verifyEquals(12, new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1,
                        new DefaultWapper().selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                                .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, new DefaultWapper().selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
                        .size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(1, listCoupon1.get(0).getiCouponUsedCount(), "验证ymt平台优惠券退回");
                Logger.verifyEquals(1, listCoupon2.get(0).getiCouponUsedCount(), "验证商家优惠券退回");

                Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0).get("CashAmount"), "验证退款金额是否等于付款金额");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"), "验证SettlementUser 为1");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementStatus"), "验证SettlementStatus 为1");
                Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"), "验证BusinessType 为3");
                Logger.verifyEquals((BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
                        (BigDecimal) settlementList.get(0).get("CouponAmount"), "验证退款结算单退回的平台CouponAmount");
            }


        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_017() {
        Logger.start(true, "已付款状态:同一主单号下1个商家的多个订单,订单全部取消,退回商家券,退回平台优惠券");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            Map map = placeOrder2();
            JSONArray orderIds = (JSONArray) map.get("orderId");
            int tradingId = (Integer) map.get("tradingId");
            BigDecimal totalAmount = BigDecimal.ZERO;
            // 创建订单
            for (int i = 0; i < orderIds.length(); i++) {
                int orderId = orderIds.getInt(i);
                totalAmount = orderService.getNeedPrePayAmountOfCash(orderId).add(totalAmount);
                OrderIdList.add(orderId);
            }
            // 买家付款
            orderService.orderPayRequest(userId, totalAmount, tradingId);
            Logger.comment("前置数据准备结束");
            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(sellerId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            // 数据库验证
            YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
            int size = OrderIdList.size();
            for (int orderId : OrderIdList) {
                // 订单主表
                List<Map> ymtOrders = database.selectOrderByOderId(orderId);
                // 订单结算
                List<Map> settlementList = database.selectYmtSettlementInvoice(orderId);
                // 付款金额
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 平台券
                String ymtCouponCode = (String) ymtOrders.get(0).get("sYmtCouponCode");
                // 商家券
                String sellerCouponCode = (String) ymtOrders.get(0).get("sSellerCouponCode");

                List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
                        .selectBysCouponCode(ymtCouponCode);
                List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
                        .selectBysCouponCode(sellerCouponCode);

                Logger.verifyEquals(12, new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1,
                        new DefaultWapper().selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                                .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, new DefaultWapper().selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
                        .size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(1, listCoupon1.get(0).getiCouponUsedCount(), "验证ymt平台优惠券不退回");
                Logger.verifyEquals(1, listCoupon2.get(0).getiCouponUsedCount(), "验证商家优惠券退回");

                Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0).get("CashAmount"), "验证退款金额是否等于付款金额");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"), "验证SettlementUser 为1");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementStatus"), "验证SettlementStatus 为1");
                Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"), "验证BusinessType 为3");
                Logger.verifyEquals((BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
                        (BigDecimal) settlementList.get(0).get("CouponAmount"), "验证退款结算单退回的平台CouponAmount");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_BatchCancelOrder_018() {
        Logger.start(true, "已付款状态:同一主单号下1个商家的多个订单,子订单没有全取消,,不退回商家券,不退回平台优惠券");
        try {
            // 参数
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            ArrayList<Integer> OrderIdList = new ArrayList<Integer>();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            Map map = placeOrder2();
            JSONArray orderIds = (JSONArray) map.get("orderId");
            int tradingId = (Integer) map.get("tradingId");
            BigDecimal totalAmount = BigDecimal.ZERO;
            // 创建订单
            for (int i = 0; i < orderIds.length(); i++) {
                int orderId = orderIds.getInt(i);
                totalAmount = orderService.getNeedPrePayAmountOfCash(orderId).add(totalAmount);
                OrderIdList.add(orderId);
            }
            OrderIdList.remove(0);
            // 买家付款
            orderService.orderPayRequest(userId, totalAmount, tradingId);
            Logger.comment("前置数据准备结束");

            batchcancelorderbean.setOrderIdList(OrderIdList);
            batchcancelorderbean.setCancelReason("自动化测试取消订单");
            batchcancelorderbean.setCancelType(CancelOrderTypeEnum.BuyerCancelOrder);
            // 卖家ID
            batchcancelorderbean.setUserId(sellerId);
            // 发送请求
            batchcancelordercall.setData(batchcancelorderbean);
            batchcancelordercall.callService();
            // 验证数据库
            DefaultWapper database = new DefaultWapper();
            // 数据库验证
            YmtCouponPrivateUserBoundWapper ymtCoupon = new YmtCouponPrivateUserBoundWapper();
            int size = OrderIdList.size();
            for (int orderId : OrderIdList) {
                // 订单主表
                List<Map> ymtOrders = database.selectOrderByOderId(orderId);
                // 订单结算
                List<Map> settlementList = database.selectYmtSettlementInvoice(orderId);
                // 付款金额
                BigDecimal totalPrice = orderService.getNeedPrePayAmountOfCash(orderId);
                // 平台券
                String ymtCouponCode = (String) ymtOrders.get(0).get("sYmtCouponCode");
                // 商家券
                String sellerCouponCode = (String) ymtOrders.get(0).get("sSellerCouponCode");

                List<YmtCouponPrivateUserBound> listCoupon1 = ymtCoupon
                        .selectBysCouponCode(ymtCouponCode);
                List<YmtCouponPrivateUserBound> listCoupon2 = ymtCoupon
                        .selectBysCouponCode(sellerCouponCode);

                Logger.verifyEquals(12, new DefaultWapper().getTradingStatus(orderId), "验证订单交易状态");
                Logger.verifyEquals(1,
                        new DefaultWapper().selectOrderTradingStatusByOrderIdAndTradingStatus(orderId, 12)
                                .size(), "验证TradingStatus表中 增加一条订单操作记录");
                Logger.verifyEquals(1, new DefaultWapper().selectOrderReasonByOrderIdAndUserId(orderId, sellerId)
                        .size(),
                        "验证Ymt_OrderReason表中增加一条订单取消原因记录");
                Logger.verifyEquals(0, listCoupon1.get(0).getiCouponUsedCount(), "验证ymt平台优惠券不退回");
                Logger.verifyEquals(0, listCoupon2.get(0).getiCouponUsedCount(), "验证商家优惠券退回");

                Logger.verifyEquals(totalPrice, (BigDecimal) settlementList.get(0).get("CashAmount"), "验证退款金额是否等于付款金额");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementUser"), "验证SettlementUser 为1");
                Logger.verifyEquals(1, settlementList.get(0).get("SettlementStatus"), "验证SettlementStatus 为1");
                Logger.verifyEquals(3, settlementList.get(0).get("BusinessType"), "验证BusinessType 为3");
                Logger.verifyEquals((BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount"),
                        (BigDecimal) settlementList.get(0).get("CouponAmount"), "验证退款结算单退回的平台CouponAmount");
            }

        } catch (Exception e) {
            Logger.fail(e);
        }
    }
}
